import Vue from 'vue'
import VueRouter from 'vue-router'
import recommend from '../views/recommend.vue'

Vue.use(VueRouter)

const routes = [
  {
    path:"/",
    redirect:"/recommend"
  },


  {
    path:"/my",
    name:"my",
    component:()=>import("../views/my.vue"),
    beforeEnter:(to,form,next)=>{
      let login = window.localStorage.getItem("token");
      //判断没有值
      if(!login){
        next("/login");
        return;
      }else{
        next();
      }
    }
  },


  {
    path:"/login",
    name:"login",
    component:()=>import("../components/login/login.vue")
  },
  {
    path:"/recommend",
    name:"recommend",
    component:recommend
  },
  {
    path:"/activity",
    name:"activity",
    component:()=>import("../views/activity.vue")
  },
  {
    path:"/baking",
    name:"baking",
    component:()=>import("../views/baking.vue")
  },
  {
    path:"/follow",
    name:"follow",
    component:()=>import("../views/follow.vue")
  },
  {
    path:"/mad",
    name:"mad",
    component:()=>import("../views/mad.vue")
  },

  {
    path:"/note",
    name:"note",
    component:()=>import("../views/note.vue")
  },
  {
    path:"/video",
    name:"video",
    component:()=>import("../views/video.vue")
  },
  {
    path:"/search",
    name:"search",
    component:()=>import("../components/base/search.vue")
  },
  {
    path:"/news",
    name:"news",
    component:()=>import("../components/base/news.vue")
  },
  {
    path:"/result",
    name:"result",
    component:()=>import("../components/base/result.vue")
  },
  {
    path:"/collection",
    name:"collection",
    component:()=>import("../components/collection/collection.vue")
  },
  {
    path:"/details",
    name:"details",
    component:()=>import("../components/base/details.vue")
  },
  {
    path:"/noteils",
    name:"noteils",
    component:()=>import("../components/base/noteils.vue")
  },
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
